/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package co.uniminuto.edu.videominuto.sessionBeans;

import co.uniminuto.edu.videominuto.entities.Usuario;
import java.util.List;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

/**
 *
 * @author Administrador
 */
@Stateless
public class UsuarioFacade extends AbstractFacade<Usuario> implements UsuarioFacadeLocal {
    @PersistenceContext(unitName = "VideoMinutoEJB")
    private EntityManager em;

    @Override
    protected EntityManager getEntityManager() {
        return em;
    }

    public UsuarioFacade() {
        super(Usuario.class);
    }
    
    public boolean validarUsuario(String login, String passwd){
    
        try{
           
            Query q= getEntityManager().createQuery("FROM Usuario u WHERE u.login = :login AND u.pass = :passwd");
            q.setParameter("passwd", passwd);
            q.setParameter("login", login);
            
            List<Usuario>  users=(List<Usuario>) q.getResultList();
            if(users.size()>0)
                return true;
            else
                return false;
            

       }catch(Exception e){
            
            e.printStackTrace();
       }
        
    return true;
    
    
    }
    
}
